package chenji.gunapi.listeners;

import org.bukkit.Bukkit;
import org.bukkit.event.Event;

import chenji.gunapi.Main;
import chenji.gunapi.events.MouseClickEvent;
import chenji.gunapi.pluginmessage.PluginMessageUntl;
import chenji.gunapi.pluginmessage.event.GunAPIPackageReceiveEvent;
import chenji.gunapi.pluginmessage.event.GunAPIPackageSendEvent;
import chenji.gunapi.pluginmessage.event.PackageListener;
import chenji.gunapi.pluginmessage.event.Priority;
import chenji.gunapi.pluginmessage.packages.InMousePackage;

public class PListener extends PackageListener {
	public PListener() {
		PluginMessageUntl.getPluginMessageUntl().getPackageManager().registerPackageListener(this, Main.getPlugin());
	}

	@Override
	public Priority getPriority() {
		return Priority.Monitor;
	}

	@Override
	public void onPackageReceive(GunAPIPackageReceiveEvent e) {
		int typeid = e.getPackage().getType();
	
		switch (typeid) {
		case 1:
			PluginMessageUntl.getPluginMessageUntl().getPlayerClientVerify().receiveVerfiy(e.getPlayer());
			return;
		case 2:
			InMousePackage p = (InMousePackage) e.getPackage();
			MouseClickEvent event = new MouseClickEvent(e.getPlayer(), p.getButton(), p.getState());
			this.callEvent(event);
			return;

		}
	}

	@Override
	public void onPackageSend(GunAPIPackageSendEvent e) {
	
	}

	private void callEvent(Event event) {
		Bukkit.getPluginManager().callEvent(event);
	}
}
